{% extends "RihabBundle::layout.html.twig" %}
{% block titre %}Type Stage{% endblock %}
{% block body %}
<div class="main">
    <div class="row">
        <div id="form-type" class="col-md-6">
            {% render (controller('StageBundle:TypeStage:new')) %}
        </div>
        <div id="list-type" class="col-md-6">
            {% render (controller('StageBundle:TypeStage:list')) %}
        </div>
    </div>
</div>

{% endblock %}
{% block js %}
{{parent()}}
<script>
    resetForm()
    function saveTypeStage() {
        $.ajax({
            type: 'POST',
            url: '{{path('stage_type_stage_new')}}',
            data: $('#form-type-stage').serialize(),
            success: function(data) {
                $('#list-type').html(data)
                resetForm()
            }
        })
    }
    function editTypeStage(id) {
        $.ajax({
            url: '{{path('stage_type_stage_new')}}',
            data: 'id=' + id,
            success: function(data) {
                $('#form-type').html(data)
            }
        })
    }
    function deleteTypeStage(id) {
        if (confirm('Voulez-vous supprimer')) {
            $.ajax({
                url: '{{path('stage_type_stage_delete')}}',
                data: 'id=' + id,
                success: function(data) {
                    $('#list-type').html(data)
                }
            })
        }
    }
    function resetForm() {
        $('#form-type-stage input').val('')
    }
</script>
{% endblock %}